/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.zjdt.epserver.db.dao4mysql;

import com.zjdt.epserver.db.dao.MyCompanyDao;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 *
 * @author dusin
 */
public class MyCompanyDaoImpl implements MyCompanyDao{

    static Logger logger = Logger.getLogger(MyCompanyDaoImpl.class);
    private JdbcTemplate jdbcTemplate;

    public MyCompanyDaoImpl(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }       
    
    @Override
    public boolean doCreate(Object[] bean) {
        boolean flag = true;
        String sql = null;
        sql = "insert into mycompany(code,name) values(?,?)";
        int rows = jdbcTemplate.update(sql, bean);
        if (rows <= 0) {
            flag = false;
        }
        return flag;
    }

    @Override
    public boolean doDeleteById(int id) {
        boolean flag = true;
        String sql = null;
        sql = "delete from mycompany where id=?";
        int rows = jdbcTemplate.update(sql, id);
        if (rows <= 0) {
            flag = false;
        }
        return flag;
    }

    @Override
    public boolean doUpdateById(Object[] bean) {
        boolean flag = true;
        String sql = null;
        sql = "update mycompany set code=?,name=? where id=?";
        int rows = jdbcTemplate.update(sql, bean);
        if (rows <= 0) {
            flag = false;
        }
        return flag;
    }  

    @Override
    public List<Map<String, Object>> findAll() {        
        String sql = "select * from mycompany";
        return jdbcTemplate.queryForList(sql);
    }
  
    @Override
    public List<Map<String, Object>> findAll4Combo() {
        String sql = "select code,name from mycompany";
        return jdbcTemplate.queryForList(sql);
    }
}
